<template>
    <div>
        <el-dialog ref="dialog" :title="$root.lang.control.device.detail.getCode" :visible.sync="showDialog" width="50%" @close="closeDialog"  :close-on-click-modal="false" :close-on-press-escape="false">
            <el-form class="tab-pan form-inline" size="small" label-position="left" :label-width="formLabelWidth">
                <el-form-item :label="($root.lang.control.device.detail.code+' :')">
                    <span>{{ baseData.code | dataFormat }}</span>
                    <el-button  type="primary" class="pull-right" style="margin-left:100px;" @click="copy()">{{ $root.lang.control.device.detail.copy }}</el-button>
                </el-form-item>
                <el-form-item :label="($root.lang.control.device.detail.expireTime+' :')">
                    <span>{{ baseData.expireTime | dateFormat }}</span>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'GetCode',
    data() {
        return {
            formLabelWidth: '120px',
            showDialog: this.show,
            baseData: this.codeData,
        }
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        deviceNumber: {
            type: String,
            default: ''
        },
        codeData: {
            type: Object,
            default: {}
        }
    },
    watch: {
        show: function (value) {
            this.showDialog = value
        },
        codeData: function(value) {
            this.baseData = value
        }
    },
    methods: {
        closeDialog() {
            this.$emit('editReceive',{
                key: 'showEdit',
                value: this.showDialog
            })
        },
        copy() {
            let _input = document.createElement("input");
            _input.value = this.codeData.code;
            document.body.appendChild(_input);
            _input.select();
            document.execCommand("Copy");
            document.body.removeChild(_input);
            this.$message({
                message: this.$root.lang.control.device.detail.copySuccess,
                type: 'success',
                duration: 3 * 1000
            })
        }, 
    },
    created() {
    }
}
</script>

<style lang="scss" scoped>

</style>
